#include <bits/stdc++.h>
using namespace std;
int T;
int n,cnt;
int a[200005];
int num(int k){
	int x=-1,y=-1,ans=0,t=1;
	while (k){
		if (k%2){
			if (a[t]!=x)x=a[t];
			else ans+=x;
		}
		else {
			if (a[t]!=y)y=a[t];
			else ans+=y;
		}
		k/=2;
		t++;
	}
	return ans;
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
	scanf("%d",&T);
	while (T--){
		cnt=0;
		scanf("%d",&n);
		for (int i=1;i<=n;i++)scanf("%d",&a[i]);
		int m=(1<<n);
		for (int i=0;i<m;i++){
			cnt=max(cnt,num(i));
		}
		printf("%d\n",cnt);
	}
	return 0;
}